package com.ccp.dev.workflow.model;

import java.util.Date;

/**
 * ClassDescribe:
 * 模型结果封装类
 * @author :wangcheng
 * Date: 2019-05-17
 */
public class ModelRepresentation {
    protected String id;
    protected String name;
    protected String key;
    protected String description;
    protected String createdBy;
    protected String category;
    protected String lastUpdatedBy;
    protected Date lastUpdated;
    protected boolean latestVersion;
    protected int version;
    protected String comment;
    protected String tenantId;

    public ModelRepresentation(ActDefModel model) {
        initialize(model);
    }

    public ModelRepresentation() {

    }

    public void initialize(ActDefModel model) {
        this.id = model.getId() + "";
        this.name = model.getName();
        this.key = model.getModelKey();
        this.description = model.getDescription();
        this.category = model.getTypeId();
        this.createdBy = model.getCreateBy();
        this.lastUpdated = model.getUpdateTime();
        this.version = model.getVersion();
        this.lastUpdatedBy = model.getUpdateBy();
        this.comment = model.getModelComment();
        this.tenantId = model.getTenantId();

        // When based on a ProcessModel and not history, this is always the latest version

        this.setLatestVersion(true);

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public Date getLastUpdated() {
        return lastUpdated;
    }

    public void setLastUpdated(Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public void setLatestVersion(boolean latestVersion) {
        this.latestVersion = latestVersion;
    }

    public boolean isLatestVersion() {
        return latestVersion;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public String getLastUpdatedBy() {
        return lastUpdatedBy;
    }

    public void setLastUpdatedBy(String lastUpdatedBy) {
        this.lastUpdatedBy = lastUpdatedBy;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getComment() {
        return comment;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public ActDefModel toModel() {
        ActDefModel model = new ActDefModel();
        model.setName(name);
        model.setDescription(description);
        return model;
    }

    /**
     * Update all editable properties of the given {@link ActDefModel} based on the values in this instance.
     */
    public void updateModel(ActDefModel model) {
        model.setDescription(this.description);
        model.setName(this.name);
        model.setModelKey(this.key);
    }
}
